package com.rental.houses.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rental.common.result.AjaxResult;
import com.rental.houses.service.ISubletHourseService;
import com.rental.model.entity.house.SubletHourse;
import com.rental.model.form.house.SubletHouseAddForm;
import com.rental.model.form.house.SubletHousePageForm;
import com.rental.model.vo.house.SubletHouseInfoVo;
import com.rental.model.vo.house.SubletHousePageVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-16
 */
@RestController
@Tag(name = "转租房屋管理")
@RequestMapping("/sublet-hourse")
public class SubletHourseController {
    @Autowired
    private ISubletHourseService subletHourseService;

    @Operation(summary = "获取当前用户的所有转租房屋信息")
    @GetMapping("/getSubletHouseListByUid/{uid}")
    public AjaxResult<List<SubletHourse>> getSubletHouseListByUid(@PathVariable("uid") Long uid) {
        return AjaxResult.success(subletHourseService.getSubletHouseListByUid(uid));
    }

    @Operation(summary = "转租房屋页面")
    @PostMapping("/getSubletHousePage/{page}/{size}")
    public AjaxResult<Page<SubletHousePageVo>> getSubletHousePage(@PathVariable("page") Integer page,
                                                                  @PathVariable("size") Integer size,
                                                                  @RequestBody SubletHousePageForm subletHousePageForm) {
        return AjaxResult.success(subletHourseService.getSubletHousePage(page, size, subletHousePageForm));
    }

    @Operation(summary = "转租房屋详情")
    @GetMapping("/{id}/{uid}")
    public AjaxResult<SubletHouseInfoVo> getSubletHouseInfoById(@PathVariable("id") Long id, @PathVariable("uid") Long uid) {
        return AjaxResult.success(subletHourseService.getSubletHouseInfoById(id, uid));
    }

    @Operation(summary = "获取联系微信")
    @GetMapping("/getContactWechat/{id}")
    public AjaxResult<String> getContactWechat(@PathVariable("id") Long id) {
        return AjaxResult.success(subletHourseService.getContactWechat(id));
    }

    @Operation(summary = "获取联系电话")
    @GetMapping("/getContactPhone/{id}")
    public AjaxResult<String> getContactPhone(@PathVariable("id") Long id) {
        return AjaxResult.success(subletHourseService.getContactPhone(id));
    }

    @Operation(summary = "下架房屋")
    @GetMapping("/downHouse/{id}/{uid}")
    public AjaxResult<Boolean> downHouse(@PathVariable("id") Long id, @PathVariable("uid") Long uid) {
        return AjaxResult.success(subletHourseService.downHouse(id, uid));
    }

    @Operation(summary = "发布转租房屋")
    @PostMapping("/addSubletHouse")
    public AjaxResult<Boolean> addSubletHouse(@RequestBody SubletHouseAddForm subletHouseAddForm) {
        return AjaxResult.success(subletHourseService.addSubletHouse(subletHouseAddForm));
    }

    @Operation(summary = "删除房屋")
    @DeleteMapping("/{id}/{uid}")
    public AjaxResult<Boolean> deleteSubletHouse(@PathVariable("id") Long id, @PathVariable("uid") Long uid) {
        return AjaxResult.success(subletHourseService.deleteSubletHouse(id, uid));
    }

    @Operation(summary = "收藏转租房屋")
    @GetMapping("/collect/{id}/{uid}")
    public AjaxResult<Boolean> collectHouse(@PathVariable("id") Long id, @PathVariable("uid") Long uid) {
        return AjaxResult.success(subletHourseService.collectHouse(id, uid));
    }

    @Operation(summary = "取消收藏转租房屋")
    @DeleteMapping("/collect/{id}/{uid}")
    public AjaxResult<Boolean> cancelCollectHouse(@PathVariable("id") Long id, @PathVariable("uid") Long uid) {
        return AjaxResult.success(subletHourseService.cancelCollectHouse(id, uid));
    }

    @Operation(summary = "根据id获取转租房屋简介")
    @GetMapping("/getSubletHousePageVo/{id}/{state}")
    public AjaxResult<SubletHousePageVo> getSubletHousePageVo(@PathVariable("id") Long id, @PathVariable("state") Integer state) {
        return AjaxResult.success(subletHourseService.getSubletHousePageVo(id, state));
    }

    @Operation(summary = "获取有效转租房源数")
    @GetMapping("/getCount")
    public AjaxResult<Long> getCount() {
        return AjaxResult.success(subletHourseService.getCount());
    }

    @Operation(summary = "举报房屋数增加")
    @GetMapping("/accusation/{id}/{userId}")
    public AjaxResult<Integer> accusation(@PathVariable("id") Long id, @PathVariable("userId") Long userId) {
        return AjaxResult.success(subletHourseService.accusation(id, userId));
    }
}
